package v1ch06.timer;

/**
 * @version 1.01 2015-05-12
 * @author Cay Horstmann
 */

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
// 解决与 java.util.Timer 的冲突

public class TimerTest {
	public static void main(String[] args) {
		ActionListener listener = new TimePrinter();
		
		// 构造一个调用监听器的定时器
		// 每 10 秒一次
		Timer t = new Timer(10000, listener);
		t.start();
		
		JOptionPane.showMessageDialog(null, "Quit program?");
		System.exit(0);
	}
}

class TimePrinter implements ActionListener {
	public void actionPerformed(ActionEvent event) {
		System.out.println("At the tone, the time is " + new Date());
		Toolkit.getDefaultToolkit().beep();
	}
}
